#include "contactlistitem.h"
#include "ui_contactlistitem.h"

ContactListItem::ContactListItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ContactListItem)
{
    ui->setupUi(this);
    installEventFilter(this);
}

ContactListItem::~ContactListItem()
{
    delete ui;
}

void ContactListItem::Selected(bool selected)
{
    ui->widget->setStyleSheet(selected ? "QWidget#widget{background: #c3c3c3;}" : "QWidget#widget{background: #e3e3e3;}");
}

void ContactListItem::Checked(bool checked)
{
    this->isSelected = checked;
}

void ContactListItem::mousePressEvent(QMouseEvent *event)
{
    Q_UNUSED(event);
    this->isSelected = true;
    Selected(true);
    emit selected(this);
}

void ContactListItem::enterEvent(QEvent *event)
{
    Q_UNUSED(event);
    Selected(true);
}

void ContactListItem::leaveEvent(QEvent *event)
{
    Q_UNUSED(event);
    if (!isSelected)
        Selected(false);
}

void ContactListItem::item(Group *data)
{
    if (data == nullptr) {
        return;
    }
    this->data = data;

    ui->nameLbl->setText(data->name());
    ui->headLbl->setPixmap(QPixmap(data->icon()));
}

Group *ContactListItem::item()
{
    return this->data;
}
